package com.prime.tutorial.moviestore.service.physicalview;

/**
 * I've got no idea, what this class does, because smn did not comment it :)<br/>
 * Created by IntelliJ IDEA. <br/>
 * User: Admin <br/>
 * Date: 21.03.2010<br/>
 * Time: 18:33:32 <br/>
 * To change this template use File | Settings | File Templates.<br/>
 * @author yevgeniuss
 */

import java.net.*;
import java.io.*;

import static java.lang.System.*;

public class URLReader {

    public String inputLine;


    public String geoCode(String address) throws Exception{

        String loc = null;

        try {
            URL googleurl = new URL("http://maps.google.com/maps/api/geocode/json?address="+ address);

            BufferedReader in = new BufferedReader(
				new InputStreamReader(
				googleurl.openStream()));


             while ((inputLine = in.readLine()) != null) {
                    //out.println(inputLine);
                    if (inputLine.contains("lat")) {loc=loc+inputLine;}
                    if (inputLine.contains("lng")) {loc=loc+inputLine;
                        loc=loc.replace(": ","=");

                        //loc= loc.replace(" ", null);
                        break;
                    }  
               }


                 in.close();
            //System.out.println(loc);

        }

        catch (MalformedURLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

        return loc;
    }
}
